package com.mall.biz.mall;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mall.client.item.TableNumService;
import com.mall.client.mall.MallService;
import com.mall.client.order.MallItemOrderService;
import com.mall.common.util.DateUtil;
import com.mall.pojo.MallItemOrder;
import com.mall.pojo.MallItemOrderExample;
import com.mall.pojo.MallItemOrderExample.Criteria;

@Service
public class ZhiHuiMallBiz {
	
	@Autowired
	private MallItemOrderService mallItemOrderService;
	@Autowired
	private TableNumService tableNumService;
	@Autowired
	private MallService mallService;

	/**
	 * 获取今天订单
	 * @param mallId
	 * @param userId
	 * @return
	 */
	public MallItemOrder getTodayMallFireOrderByUserAndTime(Long mallId,Long userId){
		List<MallItemOrder> mallItemOrderList = null;	
		MallItemOrderExample example = new MallItemOrderExample();
		example.setOrderByClause("gmt_create desc");
		Criteria criteria = example.createCriteria();
		criteria.andBuyUserIdEqualTo(userId);
		criteria.andTableNumIdEqualTo(0l);
		criteria.andMallIdEqualTo(mallId);
		criteria.andGmtCreateBetween(DateUtil.getTodayBeginTime(), DateUtil.getTodayEndTime());//取当天时间的订单
		mallItemOrderList = this.mallItemOrderService.getMallItemOrderListByExample(example);
		if (mallItemOrderList == null || mallItemOrderList.size()<=0) {
			return null;
		}
		return mallItemOrderList.get(0);
	}

//	public List<FireOrderVO> getFireOrderListByUserIdAndPage(Long userId,Page page) {
//		FireOrderExample example = new FireOrderExample();
//		example.setOrderByClause("gmt_modify desc");
//		example.setStart(page.getBegin());
//		example.setLimit(page.getLength());
//		Criteria criteria = example.createCriteria();
//		criteria.andBuyUserIdEqualTo(userId);
////		criteria.andTableNumIdNotEqualTo(0l);// 未扫桌号的订单不展示
//		criteria.andStatusNotEqualTo(-1);// -1过期订单0：未付款订单2：已付款订单 4：已经评价的订单
//		List<FireOrder> fireOrderList = this.fireOrderService.getFireOrderByExampleAndPage(example, page);
//		if (fireOrderList == null) {
//			return null;
//		}
//		List<FireOrderVO> fireOrderVOList = new ArrayList<>();
//		FireOrderVO fireOrderVO = null;
//		FireOrder fireOrder = null;
//		for (int i = 0; i < fireOrderList.size(); i++) {
//			fireOrderVO = new FireOrderVO();
//			fireOrder = fireOrderList.get(i);
//			fireOrderVO.setFireOrder(fireOrder);
//			fireOrderVO.setMall(this.mallService.getMallById(fireOrder.getMallId()));
//			fireOrderVO.setTableNum(this.tableNumService.getTableNumById(fireOrder.getTableNumId()));
//			// String itemListJson = fireOrder.getWaimaiItemsJson();
//			// List<WaiMaiTradeDetailVO> waiMaiTradeDetailVOList = null;
//			// if (itemListJson != null) {
//			// waiMaiTradeDetailVOList = JSONArray.parseArray(itemListJson,
//			// WaiMaiTradeDetailVO.class);
//			// }
//			// fireOrderVO.setWaiMaiTradeDetailVOList(waiMaiTradeDetailVOList);
//			fireOrderVOList.add(fireOrderVO);
//		}
//		if (fireOrderVOList != null && fireOrderVOList.size() > 0) {
//		fireOrderVO = fireOrderVOList.get(0);
//			}
//		return fireOrderVOList;
//	}
//
//	public Integer getFireOrderCountByUserId(Long userId) {
//		FireOrderExample example = new FireOrderExample();
//		example.setOrderByClause("gmt_modify desc");
//		
//		Criteria criteria = example.createCriteria();
//		criteria.andBuyUserIdEqualTo(userId);
////		criteria.andTableNumIdNotEqualTo(0l);// 未扫桌号的订单不展示
//		criteria.andStatusNotEqualTo(-1);
//		Integer count = this.fireOrderService.getFireOrderCountByExample(example);
//		return count;
//	}
	
}
